using System.Security.Claims;
using Crossborder.Common.Utility.HttpHelper;
using Crossborder.Core.Const;
using Crossborder.Core.Dto;
using Crossborder.Extensions.Filters;
using Crossborder.IService;
using Microsoft.AspNetCore.Mvc;

namespace Crossborder.Web.MinimalApi.Endpoint
{
    public static class ProductEndpoint
    {
        public static void UseProductEndpoint(this WebApplication app)
        {
            var gorup = app.MapGroup("api/Product/")
            .WithTags("Product")
            .RequireAuthorization(AuthorizationConst.USER)
            .AddEndpointFilter<TokenFilter>();

            #region Product

            gorup.MapGet("QueryProductInfo", async ([AsParameters] ProductInputDto dto, IProductService service) =>
            {
                var result = await service.QueryProduct(dto);
                return result;
            });

            gorup.MapGet("QueryPageProduct", async (int page, int size, [AsParameters] ProductInputDto dto, IProductService service) =>
            {
                var result = await service.QueryProductPage(page, size, dto);
                return result;
            });

            gorup.MapPost("CreateProductInfo", async ([FromBody] ProductInputDto dto, IProductService service) =>
            {
                var result = await service.CreateProduct(dto);
                return result;
            });

            #endregion

            #region Category

            gorup.MapGet("QueryCategory", async ([AsParameters] CategoryDto dto, IProductService service) =>
            {
                var result = await service.QueryCategory(dto);
                return result;
            });

            gorup.MapGet("QueryPageCategory", async (int page, int size, [AsParameters] CategoryDto dto, IProductService service) =>
            {
                var result = await service.QueryCategoryPage(page, size, dto);
                return result;
            });

            gorup.MapPost("CreateCategory", async ([FromBody] CategoryInputDto dto, IProductService service) =>
            {
                var result = await service.CreateCategory(dto);
                return result;
            });

            #endregion

            #region ProductClassify

            gorup.MapGet("QueryClassify", async ([AsParameters] ProductClassifyQueryDto dto, IProductService service) =>
            {
                var result = await service.QueryClassify(dto);
                return result;
            });


            gorup.MapGet("QueryClassifyList", async ([AsParameters] ProductClassifyQueryDto dto, IProductService service) =>
            {
                var result = await service.QueryClassifyList(dto);
                return result;
            });

            gorup.MapPost("CreateClassify", async ([FromBody] ProductClassifyInputDto dto, IProductService service) =>
            {
                var result = await service.CreateClassify(dto);
                return result;
            });
            
            #endregion
        }
    }
}